package com.hl.card.award.controller;

import com.hl.card.award.service.IManualRewardByTrans;
import com.hl.card.common.remote.user.RemoteUserService;
import com.hl.card.common.util.HttpUtils;
import com.hl.card.common.util.ResponseObject;
import com.hl.card.modular.system.service.IAccessRight;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * java类简单作用描述
 *
 * @ProjectName: distdev
 * @Package: com.hl.card.modular.pack.controller
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 作者姓名
 * @CreateDate: 2018/7/9 17:45
 * @UpdateUser: Neil.Zhou
 * @UpdateDate: 2018/7/9 17:45
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * <p>Copyright: Copyright (c) 2018</p>
 */
@RestController
@RequestMapping("/api")
public class ManualRewardByTransController {
    @Autowired
    private IManualRewardByTrans rewardByTrans;

    @Autowired
    private IAccessRight accessRight;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @PostMapping(value = "/manual/reward")
    public ResponseObject userReward(@RequestParam String userId, String parentCode, String prodCode, String amount, String count, String optId, String clientIP, String account) {
        ResponseObject reObj=new ResponseObject();
        reObj.setErroCode(1);
        reObj.setData("非法操作,请重新获取授权");
        if(accessRight.checkWxSysOptAccessRight(optId, clientIP, account)) {
            return rewardByTrans.manualReward(userId, parentCode, prodCode, amount, count, clientIP, account);
        }else {
            return reObj;
        }
    }

    @PostMapping(value = "/manual/rewardByPhone")
    public ResponseObject rewardByPhone(@RequestParam String mobile, String parentCode, String prodCode, String amount, String count, String optId, String clientIP, String account) {
        System.out.println("来访IP:" + clientIP);
        System.out.println("mobile:" + mobile);
        System.out.println("parentCode:" + parentCode);
        System.out.println("prodCode:" + prodCode);
        System.out.println("amount:" + amount);
        System.out.println("count:" + count);
        ResponseObject reObj=new ResponseObject();
        reObj.setErroCode(1);
        reObj.setData("非法操作,请重新获取授权");
        if(accessRight.checkWxSysOptAccessRight(optId, clientIP, account)) {
            return rewardByTrans.manualRewardByPhone(mobile, parentCode, prodCode, amount, count, clientIP, account);
        }else {
            return reObj;
        }
    }
}
